open Fr
open FrGui

let p2c (x, y) = int_of_float x, int_of_float y

let drawing_area ?colormap ?menu ?popup f =
	let widget = GMisc.drawing_area () in
	(* we need to not generate expose on resize *)
	let expose = lift_event true widget#event#connect#expose in
	register_e_with widget (lift begin
		let d = new GDraw.drawable ?colormap widget#misc#window in
		d#set_clip_region (GdkEvent.Expose.region %expose);
		@f d
	end);
	add_popup_menu ?menu ?popup widget;
	coerce_widget (new behavior_view_widget
		~expand: true
		widget
		(fun f ->
			(* hack to prevent GTK from reentering Fr *)
			ignore (GMain.Idle.add (fun () -> widget#misc#draw None; false)))
		f),
	lift_input ~p2c ~d2c: p2c widget#coerce widget#event
